//
//  ChangeBaseMessageViewController.m
//  1gene
//
//  Created by 1jiyin on 16/3/22.
//  Copyright © 2016年 1jiyin. All rights reserved.
//
//***********修改基本信息***********
#import "ChangeBaseMessageViewController.h"
#import "UserModel.h"
#import "YPpickViewController.h"
#import "MyViewController.h"
#import "AppDelegate.h"
@interface ChangeBaseMessageViewController ()
/*
 *滑动视图
 */
@property(nonatomic,copy)UIScrollView *myScrollView;
/*
 *scrollView内容的高度
 */
@property(nonatomic,assign)CGFloat scrollViewHeight;
/*
 *男
 */
@property(nonatomic,copy)UIButton *manBtn;
/*
 *女
 */
@property(nonatomic,copy)UIButton *womanBtn;
/*
 *男y
 */
@property(nonatomic,assign)CGFloat man_y;
/*
 *女y
 */
@property(nonatomic,assign)CGFloat woman_y;
/*
 *性别选择
 */
@property(nonatomic,assign)NSInteger sexSelected;//0男 1女
/*
 *用户头像
 */
@property(nonatomic,copy)UIImageView *userHeadImageView;
/*
 *昵称
 */
@property(nonatomic,copy)UILabel *nameLab;
/*
 *个性签名
 */
@property(nonatomic,copy)UILabel *personalNameLab;
/*
 *城市
 */
@property(nonatomic,copy)UILabel *cityLab;
/*
 *行业
 */
@property(nonatomic,copy)UILabel *businessLab;
/*
 *年龄
 */
@property(nonatomic,copy)UITextField *ageTextField;
/*
 *手机号码
 */
@property(nonatomic,copy)UITextField *telephoneTextField;
@property(nonatomic,assign)NSInteger keyBoardState;


/**
 *biaoqianLabName
 */
@property(nonatomic,copy)UILabel *biaoqianLabName;
/**
 *biaoqianImageView
 */
@property(nonatomic,copy)UIImageView *biaoqianImageView;

@property(nonatomic,copy)NSArray *biaoqianArray;


/**
 *line5
 */
@property(nonatomic,copy)UIView *line5;
/**
 *line6
 */
@property(nonatomic,copy)UIView *line6;
@property(nonatomic,copy)UIButton *changeBiaoQianBtn;;
@property(nonatomic,copy)UIButton *changeMessageBtn;

@property(nonatomic,copy)UserModel *userModel;

@property(nonatomic,copy)NSDictionary *cityDic;

@property(nonatomic,copy)UILabel *telephoneLab;


/*
 *个人信息完整度 0% 15% 30% 50% 70% 90% 100%
 */
@property(nonatomic,assign)NSInteger personalMessageState;
@end

@implementation ChangeBaseMessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:[UIView new]];
    [self initData];
    [self createUI];
    // Do any additional setup after loading the view.
}
-(void)initData
{
    _userModel=[[UserModel alloc]initWithDictionary:_dataDic];
    _biaoqianArray=[NSArray arrayWithArray:_userModel.tags];
    _cityDic=@{@"city":_userModel.user_profile[@"city"],@"province":_userModel.user_profile[@"province"]};
    _personalMessageState=2;
}
-(void)createUI
{
    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    scrollView.showsVerticalScrollIndicator=NO;
    
    UIView *headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 140)];
    headerView.backgroundColor=[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1];
    [scrollView addSubview:headerView];
    
    
    
    
    
    //返回上一页
    UIButton *backBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame=CGRectMake(10, 20+(44-25)/2.0, 25, 25);
    [backBtn setBackgroundImage:[UIImage imageNamed:@"left_back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [headerView addSubview:backBtn];
    
    //个人资料
    UILabel *personalMessageLab=[[UILabel alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 44)];
    personalMessageLab.text=@"修改基本信息";
    personalMessageLab.textColor=[UIColor whiteColor];
    personalMessageLab.font=[UIFont systemFontOfSize:22];
    personalMessageLab.textAlignment=NSTextAlignmentCenter;
    [headerView addSubview:personalMessageLab];
    
    //用户头像
    UIImageView *userHeadImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 64, 60, 60)];
    userHeadImageView.image=[UIImage imageNamed:@"155x155-1"];
    [userHeadImageView sd_setImageWithURL:[NSURL URLWithString:_userModel.user_profile[@"avatar_url"]] placeholderImage:[UIImage imageNamed:@"155x155-1"]];
    userHeadImageView.layer.cornerRadius=userHeadImageView.frame.size.width/2.0;
    userHeadImageView.layer.masksToBounds=YES;
    [headerView addSubview:userHeadImageView];
    userHeadImageView.backgroundColor = [UIColor lightGrayColor];
    _userHeadImageView=userHeadImageView;
    
    NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:_userModel.user_profile[@"avatar_url"]]];
    UIImage *myHeadImage=[UIImage imageWithData:data];
    userHeadImageView.image=myHeadImage;
    
    
    
    
    
    
    //盖按钮
    UIButton *userHeadBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    userHeadBtn.frame=userHeadImageView.frame;
    [userHeadBtn addTarget:self action:@selector(userHeadBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [headerView addSubview:userHeadBtn];
    
    
    
    //CGFloat lab_h=40;
    //昵称
    UILabel *nameLabName=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(headerView.frame)+10, 51, 30)];
    nameLabName.text=@"昵 称:";
    nameLabName.textColor=[UIColor grayColor];
    nameLabName.font=[UIFont systemFontOfSize:17];
    [scrollView addSubview:nameLabName];
    
    UILabel *nameLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(nameLabName.frame)+5, nameLabName.frame.origin.y, self.view.frame.size.width-(CGRectGetMaxX(nameLabName.frame)+5), 30)];
    nameLab.text=_userModel.user_profile[@"nikename"];
    nameLab.textColor=[UIColor grayColor];
    nameLab.font=[UIFont systemFontOfSize:15];
    nameLab.frame=CGRectMake(CGRectGetMaxX(nameLabName.frame)+5,nameLabName.frame.origin.y, self.view.frame.size.width-(CGRectGetMaxX(nameLabName.frame)+5), 30);
    [scrollView addSubview:nameLab];
    
    //修改昵称按钮
    UIButton *changeNameBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    changeNameBtn.frame=CGRectMake(self.view.frame.size.width-40, nameLab.frame.origin.y+5, 20, 20);
    [changeNameBtn setBackgroundImage:[UIImage imageNamed:@"app_right"] forState:UIControlStateNormal];
    [changeNameBtn addTarget:self action:@selector(changeNameBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:changeNameBtn];
    
    
    
    //划线
    UIView *line7=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(nameLab.frame)+10, self.view.frame.size.width, 0.5)];
    line7.backgroundColor=[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1];
    [scrollView addSubview:line7];

    //个性签名
//    UIImageView *personalNameImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(line7.frame)+5, 30, 30)];
//    personalNameImageView.image=[UIImage imageNamed:@"75x75-5"];
//    [scrollView addSubview:personalNameImageView];
    
    UILabel *personalNameLabName=[[UILabel alloc]initWithFrame:CGRectMake(10,CGRectGetMaxY(line7.frame)+10, 86, 30)];
    personalNameLabName.text=@"个性签名:";
    personalNameLabName.textColor=[UIColor grayColor];
    personalNameLabName.font=[UIFont systemFontOfSize:17];
    [scrollView addSubview:personalNameLabName];
    
    UILabel *personalNameLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(personalNameLabName.frame)+5, CGRectGetMaxY(line7.frame)+10, self.view.frame.size.width-(CGRectGetMaxX(personalNameLabName.frame)+5)-40, 30)];
    personalNameLab.text=_userModel.user_profile[@"signatures"];
    personalNameLab.textColor=[UIColor grayColor];
    personalNameLab.font=[UIFont systemFontOfSize:15];
    [scrollView addSubview:personalNameLab];
    //修改个性签名按钮
    UIButton *changePersonalNameBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    changePersonalNameBtn.frame=CGRectMake(self.view.frame.size.width-40, personalNameLab.frame.origin.y+5, 20, 20);
    [changePersonalNameBtn setBackgroundImage:[UIImage imageNamed:@"app_right"] forState:UIControlStateNormal];
    [changePersonalNameBtn addTarget:self action:@selector(changePersonalNameBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:changePersonalNameBtn];
    
    //划线
    UIView *line8=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(personalNameLab.frame)+10, self.view.frame.size.width, 0.5)];
    line8.backgroundColor=[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1];
    [scrollView addSubview:line8];
    
    
    //城市
//    UIImageView *cityImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(line8.frame)+5, 30, 30)];
//    cityImageView.image=[UIImage imageNamed:@"75x75-5"];
//    [scrollView addSubview:cityImageView];
    
    UILabel *cityLabName=[[UILabel alloc]initWithFrame:CGRectMake(10,CGRectGetMaxY(line8.frame)+10, 51, 30)];
    cityLabName.text=@"城 市:";
    cityLabName.textColor=[UIColor grayColor];
    cityLabName.font=[UIFont systemFontOfSize:17];
    [scrollView addSubview:cityLabName];
    
    UILabel *cityLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(cityLabName.frame)+5, CGRectGetMaxY(line8.frame)+10, self.view.frame.size.width-(CGRectGetMaxX(cityLabName.frame)+5), 30)];
    cityLab.text=[NSString stringWithFormat:@"%@%@",_userModel.user_profile[@"province"],_userModel.user_profile[@"city"]];
    cityLab.textColor=[UIColor grayColor];
    cityLab.font=[UIFont systemFontOfSize:15];
    [scrollView addSubview:cityLab];
    //修改城市
    UIButton *changeCityBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    changeCityBtn.frame=CGRectMake(self.view.frame.size.width-40, cityLab.frame.origin.y+5, 20, 20);
    [changeCityBtn setBackgroundImage:[UIImage imageNamed:@"app_right"] forState:UIControlStateNormal];
    [changeCityBtn addTarget:self action:@selector(changeCityBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:changeCityBtn];
    
    //划线
    UIView *line1=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(cityLab.frame)+10, self.view.frame.size.width, 0.5)];
    line1.backgroundColor=[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1];
    [scrollView addSubview:line1];
    
    //行业
//    UIImageView *businessImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(line1.frame)+5, 30, 30)];
//    businessImageView.image=[UIImage imageNamed:@"75x75-5"];
//    [scrollView addSubview:businessImageView];
    
    UILabel *businessLabName=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(line1.frame)+10, 51, 30)];
    businessLabName.text=@"行 业:";
    businessLabName.textColor=[UIColor grayColor];
    businessLabName.font=[UIFont systemFontOfSize:17];
    [scrollView addSubview:businessLabName];
    
    UILabel *businessLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(businessLabName.frame)+5, CGRectGetMaxY(line1.frame)+10, self.view.frame.size.width-(CGRectGetMaxX(businessLabName.frame)+5), 30)];
    businessLab.text=_userModel.user_profile[@"industry"];
    businessLab.textColor=[UIColor grayColor];
    businessLab.font=[UIFont systemFontOfSize:15];
    [scrollView addSubview:businessLab];
    
    
    //修改行业
    UIButton *changeBusinessBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    changeBusinessBtn.frame=CGRectMake(self.view.frame.size.width-40, businessLab.frame.origin.y+5, 20, 20);
    [changeBusinessBtn setBackgroundImage:[UIImage imageNamed:@"app_right"] forState:UIControlStateNormal];
    [changeBusinessBtn addTarget:self action:@selector(changeBusinessBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:changeBusinessBtn];
    
    
    //划线
    UIView *line2=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(businessLab.frame)+10, self.view.frame.size.width, 0.5)];
    line2.backgroundColor=[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1];
    [scrollView addSubview:line2];
    
    
    //性别
//    UIImageView *sexImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(line2.frame)+5, 30, 30)];
//    sexImageView.image=[UIImage imageNamed:@"75x75-5"];
//    [scrollView addSubview:sexImageView];
    
    UILabel *sexLabName=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(line2.frame)+10, 51, 30)];
    sexLabName.text=@"性 别:";
    sexLabName.textColor=[UIColor grayColor];
    sexLabName.font=[UIFont systemFontOfSize:17];
    [scrollView addSubview:sexLabName];
    //男
    UIButton *manBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    manBtn.frame=CGRectMake(CGRectGetMaxX(sexLabName.frame)+50, sexLabName.frame.origin.y+6, 18, 18);
    [manBtn setBackgroundImage:[UIImage imageNamed:@"myyuan_selected"] forState:UIControlStateNormal];
    [manBtn addTarget:self action:@selector(manBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:manBtn];
    _manBtn=manBtn;
    _man_y=sexLabName.frame.origin.y+4;
    
    UILabel *manLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(manBtn.frame)+5, manBtn.frame.origin.y, 18, 18)];
    manLab.text=@"男";
    manLab.font=[UIFont systemFontOfSize:15];
    manLab.textColor=[UIColor grayColor];
    [scrollView addSubview:manLab];
    
    //女
    UIButton *womanBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    womanBtn.frame=CGRectMake(CGRectGetMaxX(manLab.frame)+20, sexLabName.frame.origin.y+6, 18, 18);
    [womanBtn setBackgroundImage:[UIImage imageNamed:@"myyuan_normal"] forState:UIControlStateNormal];
    [womanBtn addTarget:self action:@selector(womanBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:womanBtn];
    _womanBtn=womanBtn;
    _woman_y=sexLabName.frame.origin.y+5;
    
    UILabel *womanLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(womanBtn.frame)+5, womanBtn.frame.origin.y, 18, 18)];
    womanLab.text=@"女";
    womanLab.font=[UIFont systemFontOfSize:15];
    womanLab.textColor=[UIColor grayColor];
    [scrollView addSubview:womanLab];
    
    
    NSInteger sex;
    if ([_userModel.user_profile[@"sex"] isKindOfClass:[NSNull class]]) {
        sex=0;
    }else{
        sex=[_userModel.user_profile[@"sex"]integerValue];
    }
    if (sex==0) {
        [manBtn setBackgroundImage:[UIImage imageNamed:@"myyuan_selected"] forState:UIControlStateNormal];
        [womanBtn setBackgroundImage:[UIImage imageNamed:@"myyuan_normal"] forState:UIControlStateNormal];
    }else{
        [manBtn setBackgroundImage:[UIImage imageNamed:@"myyuan_normal"] forState:UIControlStateNormal];
        [womanBtn setBackgroundImage:[UIImage imageNamed:@"myyuan_selected"] forState:UIControlStateNormal];
    }

    
    
    
    
    
    
    
    //划线
    UIView *line3=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(sexLabName.frame)+10, self.view.frame.size.width, 0.5)];
    line3.backgroundColor=[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1];
    [scrollView addSubview:line3];
    //年龄
//    UIImageView *ageImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(line3.frame)+5, 30, 30)];
//    ageImageView.image=[UIImage imageNamed:@"75x75-5"];
//    [scrollView addSubview:ageImageView];
    
    UILabel *ageLabName=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(line3.frame)+10, 51, 30)];
    ageLabName.text=@"生 日:";
    ageLabName.textColor=[UIColor grayColor];
    ageLabName.font=[UIFont systemFontOfSize:17];
    [scrollView addSubview:ageLabName];
    
    UILabel *ageLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(ageLabName.frame)+5, CGRectGetMaxY(line3.frame)+10, self.view.frame.size.width-(CGRectGetMaxX(ageLabName.frame)+5), 30)];
    ageLab.text=[NSString stringWithFormat:@"%@",_userModel.user_profile[@"birthday"]];
    ageLab.textColor=[UIColor grayColor];
    ageLab.font=[UIFont systemFontOfSize:15];
    //[scrollView addSubview:ageLab];
    UITextField *ageTextField=[[UITextField alloc]initWithFrame:ageLab.frame];
    ageTextField.text=[NSString stringWithFormat:@"%@",_userModel.user_profile[@"birthday"]];
    ageTextField.textColor=[UIColor grayColor];
    ageTextField.font=[UIFont systemFontOfSize:15];
    //ageTextField.clearButtonMode=UITextFieldViewModeAlways;
    ageTextField.userInteractionEnabled=NO;
    [scrollView addSubview:ageTextField];
    
    UIButton *changeAgeBtn2=[UIButton buttonWithType:UIButtonTypeCustom];
    changeAgeBtn2.frame=CGRectMake(self.view.frame.size.width-40, ageTextField.frame.origin.y+5, 20, 20);
    [changeAgeBtn2 setBackgroundImage:[UIImage imageNamed:@"app_right"] forState:UIControlStateNormal];
    changeAgeBtn2.userInteractionEnabled=NO;
    [scrollView addSubview:changeAgeBtn2];
    
    UIButton *changeAgeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    changeAgeBtn.frame=ageTextField.frame;
    [changeAgeBtn addTarget:self action:@selector(changeAgeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:changeAgeBtn];
    

    
    
    
    
    
    //划线
    UIView *line4=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(ageLabName.frame)+10, self.view.frame.size.width, 0.5)];
    line4.backgroundColor=[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1];
    [scrollView addSubview:line4];
    //手机号码
//    UIImageView *telephoneImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(line4.frame)+5, 30, 30)];
//    telephoneImageView.image=[UIImage imageNamed:@"75x75-5"];
//    [scrollView addSubview:telephoneImageView];
    
    UILabel *telephoneLabName=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(line4.frame)+10, 86, 30)];
    telephoneLabName.text=@"手机号码:";
    telephoneLabName.textColor=[UIColor grayColor];
    telephoneLabName.font=[UIFont systemFontOfSize:17];
    [scrollView addSubview:telephoneLabName];
    
    UILabel *telephoneLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(telephoneLabName.frame)+5, CGRectGetMaxY(line4.frame)+10, self.view.frame.size.width-(CGRectGetMaxX(telephoneLabName.frame)+5), 30)];
    telephoneLab.text=_userModel.user_profile[@"phone"];
    telephoneLab.textColor=[UIColor grayColor];
    telephoneLab.font=[UIFont systemFontOfSize:15];
    [scrollView addSubview:telephoneLab];
    //修改手机号码
    UIButton *changetelephoneBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    changetelephoneBtn.frame=CGRectMake(self.view.frame.size.width-40, telephoneLab.frame.origin.y+5, 20, 20);
    [changetelephoneBtn setBackgroundImage:[UIImage imageNamed:@"app_right"] forState:UIControlStateNormal];
    [changetelephoneBtn addTarget:self action:@selector(changetelephoneBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:changetelephoneBtn];
    
    
    //划线
    UIView *line5=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(telephoneLabName.frame)+10, self.view.frame.size.width, 0.5)];
    line5.backgroundColor=[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1];
    [scrollView addSubview:line5];
    _line5=line5;
    //标签
    //计算行
    NSInteger hang=[self calculatingHang:_biaoqianArray.count];
    CGFloat height1;
    if (hang<=1) {
        height1=40;
    }else{
        height1=55;
    }
    //标签
    UIImageView *biaoqianImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(line5.frame)+(height1-30)/2.0+5, 30, 30)];
    biaoqianImageView.image=[UIImage imageNamed:@"75x75-5"];
    //[scrollView addSubview:biaoqianImageView];
    _biaoqianImageView=biaoqianImageView;
    
    
    UILabel *biaoqianLabName=[[UILabel alloc]initWithFrame:CGRectMake(10, biaoqianImageView.frame.origin.y, 51, 30)];
    biaoqianLabName.text=@"标 签:";
    biaoqianLabName.textColor=[UIColor grayColor];
    biaoqianLabName.font=[UIFont systemFontOfSize:17];
    [scrollView addSubview:biaoqianLabName];
    _biaoqianLabName=biaoqianLabName;
    
    
    
    [self makeBiaoQianView:biaoqianLabName andImageView:line5 andScrollView:scrollView];
    //修改标签
    UIButton *changBiaoQianBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    changBiaoQianBtn.frame=CGRectMake(self.view.frame.size.width-40, CGRectGetMaxY(line5.frame)+(height1-20)/2.0+5, 20, 20);
    [changBiaoQianBtn setBackgroundImage:[UIImage imageNamed:@"app_right"] forState:UIControlStateNormal];
    [changBiaoQianBtn addTarget:self action:@selector(moreBiaoQianBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:changBiaoQianBtn];
    _changeBiaoQianBtn=changBiaoQianBtn;
    
    //划线
    UIView *line6=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(line5.frame)+height1+10, self.view.frame.size.width, 0.5)];
    line6.backgroundColor=[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1];
    [scrollView addSubview:line6];
    _line6=line6;
    
    //修改基本信息
    UIButton *changeMessageBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    changeMessageBtn.frame=CGRectMake((self.view.frame.size.width-(self.view.frame.size.width-20*3)/2.0)/2.0, CGRectGetMaxY(line6.frame)+30, (self.view.frame.size.width-20*3)/2.0, 40);
    changeMessageBtn.layer.borderColor=[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1].CGColor;
    changeMessageBtn.layer.cornerRadius=4.0;
    changeMessageBtn.layer.borderWidth=1.0;
    [changeMessageBtn setTitle:@"确认修改" forState:UIControlStateNormal];
    changeMessageBtn.titleLabel.font=[UIFont systemFontOfSize:20];
    changeMessageBtn.backgroundColor=[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1];
    [changeMessageBtn addTarget:self action:@selector(changeMessageBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:changeMessageBtn];
    _changeMessageBtn=changeMessageBtn;
    
    
    scrollView.contentSize=CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(changeMessageBtn.frame)+30);
    [self.view addSubview:scrollView];
    _myScrollView=scrollView;
    _scrollViewHeight=CGRectGetMaxY(changeMessageBtn.frame)+30;
    _myScrollView.contentSize=CGSizeMake(self.view.frame.size.width, _scrollViewHeight);
    
    //添加键盘通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardIsShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardIsHidden:) name:UIKeyboardWillHideNotification object:nil];
    
   // _nameTextField=nameTextField;
    //_personalNameTextField=personalNameTextField;
    //_cityTextField=cityTextField;
    //_businessTextField=businessTextField;
    _ageTextField=ageTextField;
   // _telephoneTextField=telephoneTextField;
    _nameLab=nameLab;
    _personalNameLab=personalNameLab;
    _cityLab=cityLab;
    _businessLab=businessLab;
    _telephoneLab=telephoneLab;
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(toChangeCity:) name:@"myChangeCity" object:nil];
    
}
-(void)toChangeCity:(NSNotification *)notify
{
    NSDictionary *dic=notify.userInfo;
    
    //_cityDic=@{@"city":_userModel.user_profile[@"city"],@"province":_userModel.user_profile[@"province"]};
    
    
    _cityDic=@{@"city":[NSString stringWithFormat:@"%@%@",dic[@"city"],dic[@"qu"]],@"province":dic[@"province"]};
    _cityLab.text=[NSString stringWithFormat:@"%@%@%@",dic[@"province"],dic[@"city"],dic[@"qu"]];
}



//创建标签
-(void)makeBiaoQianView:(UILabel *)biaoqianLabName andImageView:(UIView *)biaoqianImageView andScrollView:(UIScrollView *)scrollView
{
    CGFloat lab_w=(self.view.frame.size.width-10-(CGRectGetMaxX(biaoqianLabName.frame)+5)-10*2-30)/3.0;
    CGFloat lab_h=20;
    NSInteger hang=[self calculatingHang:_biaoqianArray.count];
    CGFloat lab_y;
    if (hang<=1) {
        lab_y=CGRectGetMaxY(biaoqianImageView.frame)+(40-20)/2.0;
    }else{
        lab_y=CGRectGetMaxY(biaoqianImageView.frame)+5;
    }
    for (int i=0; i<hang; i++) {
        for (int j=0; j<3; j++) {
            if (i*3+j<_biaoqianArray.count) {
                UILabel *biaoqianLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(biaoqianLabName.frame)+5+(lab_w+10)*j, lab_y+(5+lab_h)*i+5, lab_w, lab_h)];
                biaoqianLab.text=_biaoqianArray[i*3+j][@"name"];
                biaoqianLab.tag=i*3+j+1;
                biaoqianLab.textColor=[UIColor colorWithRed:87/255.0 green:187/255.0 blue:215/255.0 alpha:1];
                biaoqianLab.font=[UIFont systemFontOfSize:14];
                biaoqianLab.layer.borderColor=[UIColor colorWithRed:87/255.0 green:187/255.0 blue:215/255.0 alpha:1].CGColor;
                biaoqianLab.layer.borderWidth=1.5;
                biaoqianLab.layer.cornerRadius=4.0;
                biaoqianLab.textAlignment=NSTextAlignmentCenter;
                [scrollView addSubview:biaoqianLab];
            }
        }
        
    }
    
}
//修改年龄
-(void)changeAgeBtnClick:(UIButton *)sender
{
    YPpickViewController *picker=[[YPpickViewController alloc]init];
    picker.changeBirthday=^(NSString *birthday){
        _ageTextField.text=birthday;
    };
    [self.navigationController pushViewController:picker animated:YES];
}

//修改昵称
-(void)changeNameBtnClick:(UIButton *)sender
{
    ChangeNameViewController *vc=[[ChangeNameViewController alloc]init];
    vc.changeName=^(NSString *name){
        _nameLab.text=name;
    };
    self.navigationController.navigationBar.hidden=NO;
    [self.navigationController pushViewController:vc animated:YES];
}
//修改个性签名
-(void)changePersonalNameBtnClick:(UIButton *)sender
{
    ChangePersonalNameViewController *vc=[[ChangePersonalNameViewController alloc]init];
    vc.changeName=^(NSString *name){
        _personalNameLab.text=name;
    };
    self.navigationController.navigationBar.hidden=NO;
    [self.navigationController pushViewController:vc animated:YES];
}

//修改城市
-(void)changeCityBtnClick:(UIButton *)sender
{
    ProvinceSelectedViewController *vc=[[ProvinceSelectedViewController alloc]init];
    self.navigationController.navigationBar.hidden=NO;
    vc.changeCity=^(NSString *city){
        _cityLab.text=city;
    };
    [self.navigationController pushViewController:vc animated:YES];
}

//修改行业
-(void)changeBusinessBtnClick:(UIButton *)sender
{
    JobSelectedViewController *vc=[[JobSelectedViewController alloc]init];
    vc.returnjobSelected=^(NSString *jobName){
        _businessLab.text=jobName;
    };
    self.navigationController.navigationBar.hidden=NO;
    [self.navigationController pushViewController:vc animated:YES];
}

//修改手机号码
-(void)changetelephoneBtnClick:(UIButton *)sender
{
    ChangeTelephoneViewController *vc=[[ChangeTelephoneViewController alloc]init];
    self.navigationController.navigationBar.hidden=NO;
    vc.returnTelephone=^(NSString *telephone){
        _telephoneLab.text=telephone;
    };
    [self.navigationController pushViewController:vc animated:YES];
}




//manBtnClick
-(void)manBtnClick:(UIButton *)sender
{
    _sexSelected=0;
    //_manBtn.frame=CGRectMake(_manBtn.frame.origin.x, _manBtn.frame.origin.y, 22, 22);
    [_manBtn setBackgroundImage:[UIImage imageNamed:@"myyuan_selected"] forState:UIControlStateNormal];
    //_womanBtn.frame=CGRectMake(_womanBtn.frame.origin.x, _womanBtn.frame.origin.y, 22, 22);
    [_womanBtn setBackgroundImage:[UIImage imageNamed:@"myyuan_normal"] forState:UIControlStateNormal];

    
}

//用户头像点击
-(void)userHeadBtnClick:(UIButton *)sender
{
    HeadImageSelectedViewController *vc=[[HeadImageSelectedViewController alloc]init];
    vc.tabbarState=1;
    self.navigationController.navigationBar.hidden=NO;
    self.tabBarController.tabBar.hidden=YES;
    vc.returnSelectedImage=^(UIImage *img){
        _userHeadImageView.image=img;
    };
    
    [self.navigationController pushViewController:vc animated:YES];
    
}

//womanBtnClick
-(void)womanBtnClick:(UIButton *)sender
{
    //    manImageView.image=[UIImage imageNamed:@"danxuan2"];
    //    womanImageView.image=[UIImage imageNamed:@"iconfont-xuanzekuang"];
    _sexSelected=1;
   // _manBtn.frame=CGRectMake(_manBtn.frame.origin.x, _manBtn.frame.origin.y, 22, 22);
    [_manBtn setBackgroundImage:[UIImage imageNamed:@"myyuan_normal"] forState:UIControlStateNormal];
    //_womanBtn.frame=CGRectMake(_womanBtn.frame.origin.x, _womanBtn.frame.origin.y, 22, 22);
    [_womanBtn setBackgroundImage:[UIImage imageNamed:@"myyuan_selected"] forState:UIControlStateNormal];
}
//显示键盘
-(void)keyboardIsShow:(NSNotification *)notify
{
    
    NSDictionary *dic=notify.userInfo;
    NSLog(@"===========%@",dic);
    CGRect frame=[[dic objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    if (_keyBoardState==0) {
         _myScrollView.contentSize=CGSizeMake(self.view.frame.size.width, _myScrollView.contentSize.height+frame.size.height);
    }
    _keyBoardState++;
}

//隐藏键盘
-(void)keyboardIsHidden:(NSNotification *)notify
{
    _myScrollView.contentSize=CGSizeMake(self.view.frame.size.width, _scrollViewHeight);
    _keyBoardState=0;
}

//修改基本信息
-(void)changeMessageBtnClick:(UIButton *)sender
{
    NSLog(@"确认修改");
    [self changeMessageHttpData];
}
//返回上一页
-(void)backBtnClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//根据文字计算宽度和高度
-(CGFloat)calculateWidthWithLable:(UILabel *)label
{
    CGSize size=[label.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:label.font,NSFontAttributeName, nil]];
    return size.width;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.navigationController.view endEditing:YES];
}

//更多标签
-(void)moreBiaoQianBtnClick:(UIButton *)sender
{
    AddBiaoQianViewController *vc=[[AddBiaoQianViewController alloc]init];
    vc.tagsArray=[NSArray arrayWithArray:_dataDic[@"tags"]];
    vc.allSystemArray=[NSArray arrayWithArray:_systemArray];
    self.navigationController.navigationBar.hidden=NO;
    vc.changeBiaoQian=^(NSArray *arr){
        
        
        
        for (int i=0; i<_biaoqianArray.count; i++) {
            UILabel *lab=(id)[_myScrollView viewWithTag:i+1];
            [lab removeFromSuperview];
        }
        
        _biaoqianArray=arr;
        
        //计算行
        NSInteger hang=[self calculatingHang:_biaoqianArray.count];
        CGFloat height1;
        if (hang<=1) {
            height1=40;
        }else{
            height1=55;
        }
        //标签
        //_biaoqianImageView.frame=CGRectMake(10, CGRectGetMaxY(_line5.frame)+(height1-30)/2.0, 30, 30);
        _biaoqianLabName.frame=CGRectMake(10, CGRectGetMaxY(_line5.frame)+(height1-30)/2.0, 51, 30);
        _changeBiaoQianBtn.frame=CGRectMake(self.view.frame.size.width-40, CGRectGetMaxY(_line5.frame)+(height1-20)/2.0, 20, 20);
        _line6.frame=CGRectMake(0, CGRectGetMaxY(_line5.frame)+height1+10, self.view.frame.size.width, 0.5);
        _changeMessageBtn.frame=CGRectMake((self.view.frame.size.width-(self.view.frame.size.width-20*3)/2.0)/2.0, CGRectGetMaxY(_line6.frame)+30, (self.view.frame.size.width-20*3)/2.0, 40);
        _scrollViewHeight=CGRectGetMaxY(_changeMessageBtn.frame)+30;
        _myScrollView.contentSize=CGSizeMake(self.view.frame.size.width, _scrollViewHeight);
        
        [self makeBiaoQianView:_biaoqianLabName andImageView:_line5 andScrollView:_myScrollView];
    };
    [self.navigationController pushViewController:vc animated:YES];
}
//计算行
-(NSInteger)calculatingHang:(NSInteger)number
{
    NSInteger hang;
    if (number%3==0) {
        hang=number/3;
    }else{
        hang=number/3+1;
    }
    return hang;
}

//修改基本信息
-(void)changeMessageHttpData
{
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    NSString *token= [user objectForKey:@"token"];
    NSString *sex;
    
    if (_sexSelected==0) {
        sex=@"0";
    }else{
        sex=@"1";
    }
    
    [self.view isLoading:YES];
    NSDictionary *params=@{@"phone":[NSString stringWithFormat:@"%@",_telephoneLab.text],@"nikename":_nameLab.text,@"sex":sex,@"birthday":[NSString stringWithFormat:@"%@",_ageTextField.text],@"signatures":[NSString stringWithFormat:@"%@",_personalNameLab.text],@"industry":[NSString stringWithFormat:@"%@",_businessLab.text],@"province":_cityDic[@"province"],@"city":[NSString stringWithFormat:@"%@",_cityDic[@"city"]]};
    [manager POST:[NSString stringWithFormat:ChangeBaseMessage,token] parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        //第一步是将图片转换成二进制数据流
        //NSData * photoData = UIImagePNGRepresentation((id)_dataArray[i]);
        //由于上传的图片是JPG格式的，所以用下面的方法
        NSData * photoData = UIImageJPEGRepresentation(_userHeadImageView.image, 0.5);
        // 获得一个永不重复的随机的字符串
        NSString * imageName =[[NSUUID UUID] UUIDString];
        
        [formData appendPartWithFileData:photoData name:@"avatar" fileName:imageName mimeType:@"image/jpeg"];
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [self.view isLoading:NO];
        
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"修改的信息%@",dic);
        [self awardScore];
        
        AppDelegate *app=[UIApplication sharedApplication].delegate;
        [app myClearCacheAction];
        
        MyViewController *vc=[[MyViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self.view isLoading:NO];
        [self.view showTiShiMessage:@"修改失败"];
        NSLog(@"error%@",error.localizedDescription);
    }];
    
}

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden=YES;
}
//计算信息完整度
-(void)calculateMessageNumber
{
    NSString *name=[NSString stringWithFormat:@"%@",_nameLab.text];
    
    NSString *personalName=[NSString stringWithFormat:@"%@",_personalNameLab.text];
    
    NSString *city=[NSString stringWithFormat:@"%@",_cityLab.text];
    
    NSString *job=[NSString stringWithFormat:@"%@",_businessLab.text];
    
    NSString *age=[NSString stringWithFormat:@"%@",_ageTextField.text];
    
    NSString *telephone=[NSString stringWithFormat:@"%@",_telephoneTextField.text];
    
    if (name.length>0) {
        _personalMessageState+=1;
    }
    if (personalName.length>0) {
        _personalMessageState+=1;
    }
    if (city.length>0) {
        _personalMessageState+=1;
    }
    if (job.length>0) {
        _personalMessageState+=1;
    }
    if (age.length>0) {
        _personalMessageState+=1;
    }
    if (telephone.length>0) {
        _personalMessageState+=1;
    }
}
//根据修改信息的完整度来奖励积分
-(void)awardScore
{
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    NSInteger gotScore=[[NSString stringWithFormat:@"%@",[user objectForKey:@"got_credit"]]integerValue];
    if (gotScore==0) {
        if (_personalMessageState>=4&&_personalMessageState<8) {
            [self.view showTiShiMessage:@"奖励5积分!"];
            return;
        }
    }
    if (gotScore==5) {
        if (_personalMessageState==8) {
            [self.view showTiShiMessage:@"奖励10积分!"];
            return;
        }
    }
    [self.view showTiShiMessage:@"修改成功"];
    
}

//系统标签
-(void)getSystemBiaoQian
{
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
